/**
* Created by admin on 2018/3/10.
*/
<template>
  <section class="orderBox">
    <el-form :model="userInfo" :rules="userRules" ref="userInfo" label-width="100px" class="demo-userInfo">
      <el-row>
        <el-col :span="7" :offset="1">
          <el-form-item label="姓名" prop="realName">
            <el-input v-model="userInfo.realName" :disabled="userDisable" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="学号" prop="stuNo">
            <el-input v-model="userInfo.stuNo" :disabled="userDisable" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="邮箱" prop="email">
            <el-input v-model="userInfo.email" :disabled="userDisable" clearable></el-input>
          </el-form-item>
        </el-col>

      </el-row>

      <el-row>
        <el-col :span="7" :offset="1">
          <el-form-item label="手机号" prop="mobileNumber">
            <el-input v-model="userInfo.mobileNumber" :disabled="userDisable" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="性别" prop="sex">
            <el-select v-model="userInfo.sex" :disabled="userDisable" clearable>
              <el-option label="男" :value="1" :key="1"></el-option>
              <el-option label="女" :value="2" :key="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="7">
          <el-form-item label="政治面貌" prop="political">
            <el-select v-model="userInfo.political" :disabled="userDisable" clearable>
              <el-option label="中国共产主义青年团团员" :value="1" :key="1"></el-option>
              <el-option label="中国共产党党员" :value="2" :key="2"></el-option>
              <el-option label="群众" :value="3" :key="3"></el-option>
              <el-option label="民主党派" :value="4" :key="4"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="8" :offset="1">
          <el-form-item label="专业" prop="schoolMajor">
            <el-cascader v-model="userInfo.schoolMajor" :disabled="userDisable"
              placeholder="试试搜索：软件工程"
              :options="options"
              filterable clearable style="width: 250px;"
            ></el-cascader>
          </el-form-item>
        </el-col>

    </el-row>

      <el-row>
        <el-col :span="12" :offset="6">
          <el-form-item>
          <el-button type="primary" @click="editForm">编辑</el-button>
          <el-button type="success" @click="userFormSubmit('userInfo')">保存</el-button>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <div class="divid-line"></div>

    <el-row>
      <div class="one-title">个人证书</div>
      <div class="cardImg" v-for="(item,index) in picList">
        <ml-photo-box ref='photoBox'></ml-photo-box>
        <img :src="item.url" @click.stop="attachmentUrl(picList[0])"><br>{{item.name}}
      </div>
    </el-row>
    <div class="divid-line"></div>

    <el-row>
      <div class="one-title">我的募捐</div>
      <el-table :data="funMoney" width="100%"  @row-click="rowClick" size="large">
        <el-table-column type="index" label="序号" width="200" ></el-table-column>
      <el-table-column prop="title"  label="活动标题"></el-table-column>
      <el-table-column prop="funTime" width="500" label="募捐时间">
      <template scope="scope">
      <span>{{getdate(scope.row.funTime)}}</span>
      </template>
      </el-table-column>
      <el-table-column prop="money" label="募捐金额"></el-table-column>
      </el-table>
    </el-row>

</section>
</template>
<script>
  import DataUtil from '../../common/dataUtil.js'
  import ElRow from "element-ui/packages/row/src/row";
  import ElCol from "element-ui/packages/col/src/col";
  import mlPhotoBox from '../../components/_photoBox.vue'
  export default {
    components: {
      ElCol,
      ElRow,
      mlPhotoBox,
    },
    data() {
      var emaliValitor = (rule, value, callback) => {
        var regex = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
        if (value === '') {
          callback(new Error('邮箱不能为空！'));
        } else if (!regex.test(value)) {
          callback(new Error('邮箱格式不合法！'));
        } else {
          callback();
        }
      };
      var sexValitor = (rule, value, callback) => {
        if (value === 0) {
          callback(new Error('请选择性别！'));
        } else {
          callback();
        }
      };
      var politicalValitor = (rule, value, callback) => {
        if (value === 0) {
          callback(new Error('请选择政治面貌！'));
        } else {
          callback();
        }
      };
      return {
        funMoney: [],
        userInfo: {
          realName: '',
          stuNo: '',
          sex: 1,
          major: '',
          grade: '',
          school: '',
          email: '',
          political: 3,
          mobileNumber:'',
          userRole: 1,
          schoolMajor:'',
        },
        upLoadData: {
          userId: DataUtil.id()
        },
        fileName:"",
        fileList:[

        ],
        picList:[],
        userDisable: true,
        userRules: {
          realName: [
            { required: true, message: '姓名不能为空！', trigger: 'blur' },
          ],
          stuNo: [
            { required: true, message: '学号不能为空！', trigger: 'blur' }
          ],
          sex: [
            { required: true, validator: sexValitor, trigger: 'blur' }
          ],
          major: [
            { required: true, message: '专业不能为空！', trigger: 'blur' }
          ],
          email: [
            { required: true, validator: emaliValitor, trigger: 'blur' }
          ],
          political: [
            { required: true, validator: politicalValitor, trigger: 'blur' }
          ],
          mobileNumber: [
            { required: true, message: '请填写手机号！', trigger: 'blur' }
          ]
        },
        options: [{
          value: '合肥学院',
          label: '合肥学院',
          children: [{
            value: '一年级',
            label: '一年级',
            children: [{
              value: '软件工程',
              label: '软件工程'
            }, {
              value: '网络工程',
              label: '网络工程'
            }, {
              value: '计本1',
              label: '计本1'
            }, {
              value: '计本2',
              label: '计本2'
            }]
          }, {
            value: '二年级',
            label: '二年级',
            children: [{
              value: '软件工程',
              label: '软件工程'
            }, {
              value: '网络工程',
              label: '网络工程'
            }, {
              value: '计本1',
              label: '计本1'
            }, {
              value: '计本2',
              label: '计本2'
            }]
          },{
            value: '三年级',
            label: '三年级',
            children: [{
              value: '软件工程',
              label: '软件工程'
            }, {
              value: '网络工程',
              label: '网络工程'
            }, {
              value: '计本1',
              label: '计本1'
            }, {
              value: '计本2',
              label: '计本2'
            }]
          },{
            value: '四年级',
            label: '四年级',
            children: [{
              value: '软件工程',
              label: '软件工程'
            }, {
              value: '网络工程',
              label: '网络工程'
            }, {
              value: '计本1',
              label: '计本1'
            }, {
              value: '计本2',
              label: '计本2'
            }]
          }]
        }]
      };
    },
    methods: {

      attachmentUrl(item){
        if(item.url){
          let _photoList = [
            item.url
          ];
          this.$refs.photoBox.show(_photoList)
        }
      },
      getdate(dates) {
        if(!dates){
          return '';
        }
        var myDate = new Date(dates);
        let minute=myDate.getMinutes();
        if(minute<10){
          minute="0"+minute;
        }
        let seconds=myDate.getSeconds()
        if(seconds<10){
          seconds="0"+seconds;
        }
        return myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate()+" "+myDate.getHours()+":"+minute+":"+seconds
      },
      userFormSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let _data = Object.assign({}, this.userInfo);
            let temp = _data.schoolMajor;
            _data.school = temp[0];
            _data.grade = temp[1];
            _data.major = temp[2];
            this.$http.post('user/insertOrUpdateUser', _data).then(response => {
               if (response.body.code == 1) {
                     this.$message({
                       type : 'success',
                       message : '修改个人信息成功！'
                     })
                 this.userDisable = true;
                 }
            });
          } else {
            this.$message.error('请完善个人信息！');
            return false;
          }
        });
      },
      editForm() {
        this.userDisable = false;
      },
      getUserInfo(){

          this.$http.post('user/getUserById',{'id':DataUtil.id()}).then(response => {
             if (response.body.code == 1) {
                 this.userInfo = response.body.data;
             }
          });

      },
      getAllCheckData() {
        this.$http.post('check/getAllOrginzeData', {userId: DataUtil.id(), type: 4, fileType: 1}).then(response => {
          if (response.body.code == 1) {
            this.picList = response.body.data;
          }
        });
      },
      getPersonFun() {
          this.$http.post('pay/getPersonFun', {userId: DataUtil.id()}).then(response => {
              if (response.body.code == 1) {
                this.funMoney = response.body.data;
              } else {
                  this.$message.error(response.body.message);
              }
          });
      }
    },
    mounted: function () {
      this.getUserInfo();
      this.getAllCheckData();
      this.getPersonFun();
    }
  }
</script>


  <style>
  .reviewTable {
    width: 80%;
    border-spacing: 0;
    border: 1px solid gray;
    margin: 20px auto;
  }
  .reviewTable td {
    text-align: center;
    border: 1px solid gray;
    height: 40px;
    line-height: 40px;

    width: 50%;
    word-wrap:break-word;
  }
  .videos {
    width: 80%;
    margin: 20px auto;
  }
  .cardImg {
    width: 40%;
    height: 300px;
    overflow: hidden;
    margin: 1.5%;
    float: left;
    text-align: center;
  }
  /*.faceCheck .faceImg img {*/
    /*margin: 0 auto;*/
    /*display: block;*/
    /*width: 90%;*/
    /*height: 90%;*/
  /*}*/
  /*侧边框布局*/
  .containers {
    width: 100%;
    /*height: 400px;*/
    display: flex;

  }
  .containers .asides {
    flex: 6;

  }
  .containers .mains {
    flex: 4;
    margin-left: 40px;
  }
  .other_remark {
    width: 100%;
  }
  .mains .smallRemark {
    width: 100%;
  }
  .asides table {
    border-spacing: 0;
    border: 1px solid #A9A9A9 ;
    border-radius: 2px;
  }
  .asides table td {
    border: .5px solid #efefef;
    word-wrap:break-word;
    line-height: 20px;
    padding: 5px;
  }
  table td img {
    width: 100%;
  }
  .aside_title {
    font-weight: 400;
    line-height: 40px;
    font-size: 16px;
  }
  .question_radio {
    padding-bottom: 30px;
    margin: 5px 10px;
  }
  .question_radio .radio_box {
    /*margin-bottom: -30px;*/
    line-height: 20px;
    float: right;
  }
  .addreBook {
    text-align: center;
    width: 40px;
  }
  /* 标题 */
  .main-title{
    font-size: 22px;
    margin-top: -15px;
    margin-bottom: 15px;
  }
  .one-title{
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 7px;
  }
  .two-title{
    font-size: 13px;
    color: #888;
    margin: 10px 0
  }
  .subtitle{
    font-size: 13px;
    color: #888;
  }
  .orderBox .el-row {
    margin: 8px 30px;
  }
  .orderBox .el-col span{
    margin-right: 10px;
  }
  .orderBox .el-button span,.orderBox .el-tag span{
    margin-right: 0;
  }
  .orderBox .box-card .el-button{
    margin-right: 5px;
  }
  .orderBox .grid-content {
    line-height: 28px;
  }

  .divid-line{
    height: 10px;
    background: #f1f2f7;
  }
  /*借款信息*/
  .loanDetail{
    margin: 0 30px 15px;
    width: 94%;
    max-height:250px;
  }
  /*依图识别*/
  .yituInfo{
    display: block;
    text-align: center;
    margin-top: 10px;
  }
  /*征信*/
  .orderBox .box-card{
    height: 225px;
  }
  .JXLBox{
    border: 1px solid #ccc;
    padding: 10px
  }
  .JXLBox div{
    padding: 5px;
  }

  .orderBox .el-table .info-row {
    background: #e2f0e4;
  }

  .orderBox .el-table .red-row{
    background: #F33;
  }
  .redInfo{
    color: #F33;
  }

  .line-height .el-col{
    margin-bottom: 10px;
  }
  .faceCheck {
    margin: 0 auto;
    overflow: hidden;
  }
  .faceCheck .faceImg{
    width: 45%;
    height: 350px;
    overflow: hidden;
    margin: 1.5%;
    float: left;
    text-align: center;
  }
  .faceCheck .faceImg img {
    margin: 0 auto;
    display: block;
    width: 90%;
    height: 90%;
/*    border: .5px solid #F1F2F7;
border-radius: 5px;*/
}
.faceImgTop img{
  margin: 0 auto;
  height: 200px;
  display: block;
  max-height: 100%;
  max-width: 100%;
  min-width: 65%;
  min-height: 65%;
  border: .5px solid #F1F2F7;
  border-radius: 5px;
}
.faceImgBottom img{
  margin: 0 auto;
  display: block;
  height: 300px;
  min-width: 80%;
  min-height: 80%;
  border: .5px solid #F1F2F7;
  border-radius: 5px;
}
table td img {
  width: 100%;
}
.faceImgTop .handleImg {
  width: 40%;
  transform: rotate(-90deg);
  -webkit-transform: rotate(-90deg);
}
</style>
